import { defineStore } from 'pinia';
import { StorageEnum } from '@2/app/core/storage/storage.enum';
import { store } from '@/store';
import { PermissionState } from '@2/app/core/storage/permission.storage';

/**
 * 用于定义许可授权存储
 * @return 定义许可授权存储，（不能为 undefined）
 */
const defineStorage = defineStore({
  id: StorageEnum.PERMISSION_STORE_NAME,
  state: (): PermissionState => ({
    authorities: [],
    dynamicAddedRoute: false,
    lastBuildMenuTime: 0,
    backMenuList: [],
    frontMenuList: [],
  }),
});

/**
 * 用于需要在设置之外使用，定义许可授权存储
 * @return 定义许可授权存储，（不能为 undefined）
 */
export function permissionDefineStore() {
  return defineStorage(store);
}
